{extend name="admin/base" /}
{block name="resources"/}

{/block}
{block name="main"}
<input type="hidden" id="order_id"/>
<input type="hidden" id="order_goods_id"/>
<input type="hidden" id="order_status" value="{$status}"/>
<input type="hidden" id="refund_status" value="{$refund_status}"/>

<form class="v-filter-container">
    <div class="filter-fields-wrap">
        <div class="filter-item clearfix">
            <div class="filter-item__field">
                <div class="v__control-group">
                    <label class="v__control-label">订单编号</label>
                    <div class="v__controls">
                        <input type="text" id="order_no" class="v__control_input" placeholder="请输入订单编号" autocomplete="off">
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">商品名称</label>
                    <div class="v__controls">
                        <input type="text" class="v__control_input" id="goods_name" placeholder="请输入商品名称" autocomplete="off">
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">快递单号</label>
                    <div class="v__controls">
                        <input type="text" class="v__control_input" id="express_no" placeholder="请输入快递单号" autocomplete="off">
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">会员信息</label>
                    <div class="v__controls">
                        <input type="text" class="v__control_input" id="user_info" autocomplete="off" placeholder="手机号码/会员ID/用户名/昵称">
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">支付方式</label>
                    <div class="v__controls">
                        <select class="v__control_input" id="payment_type">
                            <option value="">全部</option>
                            <option value="1">微信</option>
                            <option value="2">支付宝</option>
                            <option value="3">银行卡</option>
                            <option value="5">余额支付</option>
                            <option value="16">eth支付</option>
                            <option value="17">eos支付</option>
                        </select>
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">订单类型</label>
                    <div class="v__controls">
                        <select class="v__control_input" id="order_type">
                            <option value="">全部</option>
                            {volist name="orderTypeList" id="ot"}
                            <option value="{$ot['type_id']}">{$ot['type_name']}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">下单时间</label>
                    <div class="v__controls v-date-input-control">
                        <label for="orderTime">
                            <input type="text" class="v__control_input pr-30" id="orderTime" placeholder="请选择时间" autocomplete="off" data-types="datetime">
                            <i class="icon icon-calendar"></i>
                            <input type="hidden" id="orderStartDate">
                            <input type="hidden" id="orderEndDate">
                        </label>
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">付款时间</label>
                    <div class="v__controls v-date-input-control">
                        <label for="payTime">
                            <input type="text" class="v__control_input pr-30" id="payTime" placeholder="请选择时间" autocomplete="off" data-types="datetime">
                            <i class="icon icon-calendar"></i>
                            <input type="hidden" id="payStartDate">
                            <input type="hidden" id="payEndDate">
                        </label>
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">发货时间</label>
                    <div class="v__controls v-date-input-control">
                        <label for="deliveryTime">
                            <input type="text" class="v__control_input pr-30" id="deliveryTime" placeholder="请选择时间" autocomplete="off" data-types="datetime">
                            <i class="icon icon-calendar"></i>
                            <input type="hidden" id="sendStartDate">
                            <input type="hidden" id="sendEndDate">
                        </label>
                    </div>
                </div>
                <div class="v__control-group">
                    <label class="v__control-label">完成时间</label>
                    <div class="v__controls v-date-input-control">
                        <label for="completeTime">
                            <input type="text" class="v__control_input pr-30" id="completeTime" placeholder="请选择时间" autocomplete="off" data-types="datetime">
                            <i class="icon icon-calendar"></i>
                            <input type="hidden" id="finishStartDate">
                            <input type="hidden" id="finishEndDate">
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="filter-item clearfix">
            <div class="filter-item__field">
                <div class="v__control-group">
                    <label class="v__control-label"></label>
                    <div class="v__controls">
                        <a class="btn btn-primary" id="search_button"><i class="icon icon-search"></i> 搜索</a>
                        <a class="btn btn-success ml-15" id="export_button">导出EXCEL</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<div class="screen-title"><span class="text">订单列表</span></div>

<div class="infoTab">
    <ul id="myTab" class="nav nav-tabs v-nav-tabs">
        <li class="{if $refund_status == 9}active{/if}">
            <a href="{:__URL('ADMIN_MAIN/order/afterorderlist?refund_status=9')}">
                <p>全部</p>
                <p id="all_refund"></p>
            </a>
        </li>
        <li class="{if $refund_status == 0}active{/if}">
            <a href="{:__URL('ADMIN_MAIN/order/afterorderlist?refund_status=0')}">
                <p>待买家操作</p>
                <p id="waiting_buyer_operation"></p>
            </a>
        </li>
        <li class="{if $refund_status == 1}active{/if}">
            <a href="{:__URL('ADMIN_MAIN/order/afterorderlist?refund_status=1')}">
                <p>待卖家操作</p>
                <p id="waiting_seller_operation"></p>
            </a>
        </li>
        <li class="{if $refund_status == 2}active{/if}">
            <a href="{:__URL('ADMIN_MAIN/order/afterorderlist?refund_status=2')}">
                <p>已退款</p>
                <p id="have_refunded"></p>
            </a>
        </li>
        <li class="{if $refund_status == 3}active{/if}">
            <a href="{:__URL('ADMIN_MAIN/order/afterorderlist?refund_status=3')}">
                <p>已拒绝</p>
                <p id="have_refused"></p>
            </a>
        </li>
    </ul>

    <div id="myTabContent" class="tab-content">
        {foreach name="child_menu_list" item="child_menu" key="k" }
        <div class="tab-pane fade {eq name='child_menu.active' value='1'}in active{/eq}">
            <!--表格-->
            <table class="table table-hover v-table mb-10">
                <thead>
                <tr>
                    <th class="col-md-3">商品</th>
                    <th class="col-md-1">单价</th>
                    <th class="col-md-1">数量</th>
                    <th class="col-md-2">买家/收货人</th>
                    <th class="col-md-1">订单状态</th>
                    <th class="col-md-2 operationLeft">实收</th>
                    <th class="col-md-2 pr-14 operationLeft">操作</th>
                </tr>
                </thead>
            </table>
            <div class="tables ol_tbody" id="list">

            </div>
            <div class="page clearfix">
                <div class="M-box3 m-style fr">
                </div>
            </div>
        </div>
        {/foreach}
    </div>
</div>
<!-- page end -->

<!-- 处理回寄模态框（Modal） -->
<div class="modal fade" id="confirm_receipt" tabindex="-1" role="dialog" aria-labelledby="myModalLabelReceipt"
     aria-hidden="true">
    <div class="modal-dialog" style="width:550px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabelReceipt">订单备注</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">

                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">处理结果</label>
                        <div class="col-sm-6">
                            <label class="radio-inline">
                                <input type="radio" name="dealResult" id="confirm" value="0" checked> 确认签收
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="dealResult" id="refuse" value="1"> 拒绝签收
                            </label>
                        </div>
                    </div>

                    <div class="form-group isBlock hide">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">拒绝原因</label>
                        <div class="col-sm-6">
                            <textarea class="form-control ta_resize" rows="4" id="refuse_receipt_reason"
                                      placeholder="原因"></textarea>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary add1" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>

    </div>
</div>
<!-- /.modal -->

<!-- 处理退款申请模态框（Modal） -->
<div class="modal fade" id="judge_refund" tabindex="-1" role="dialog" aria-labelledby="myModalLabelJudgeRefund"
     aria-hidden="true">
    <div class="modal-dialog" style="width:550px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabelJudgeRefund">处理退款申请</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">售后类型</label>
                        <div class="col-sm-6">
                            <p class="form-control-static">退款</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">处理结果</label>
                        <div class="col-sm-6">
                            <label class="radio-inline">
                                <input type="radio" name="goodsRefund" id="refund_agree" value="1" checked> 同意退款
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="goodsRefund" id="refund_disagree" value="0"> 拒绝退款
                            </label>
                        </div>
                    </div>

                    <div class="form-group reason hide">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">拒绝原因</label>
                        <div class="col-sm-6">
                            <textarea class="form-control ta_resize" rows="4" name="reason" id="judge_refund_reason"
                                      placeholder="原因"></textarea>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary add2" data-dismiss="modal">确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>

    </div>
</div>
<!-- /.modal -->

<!-- 处理退货申请模态框（Modal） -->
<div class="modal fade" id="judge_return" tabindex="-1" role="dialog" aria-labelledby="myModalLabelJudgeReturn"
     aria-hidden="true">
    <div class="modal-dialog" style="width:550px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabelJudgeReturn">处理退货申请</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">售后类型</label>
                        <div class="col-sm-7">
                            <p class="form-control-static">退款</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">处理结果</label>
                        <div class="col-sm-7">
                            <label class="radio-inline">
                                <input type="radio" name="goodsReturn" id="return_agree" value="1" checked> 同意退货
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="goodsReturn" id="return_disagree" value="0"> 拒绝退货
                            </label>
                        </div>
                    </div>

                    <div class="form-group returnAddress">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">退货地址</label>
                        <div class="col-sm-7" style="padding-top: 8px">
							<select class="form-control" id="address_return"><option value="0">请选择地址</option></select>
							<p class="help-block">没有退货地址？前往系统》商城配置》商家地址添加</p>
                        </div>
                    </div>

                    <div class="form-group reason hide">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-3 control-label">拒绝原因</label>
                        <div class="col-sm-7">
                            <textarea class="form-control ta_resize" rows="4" id="reject_return_reason"
                                      placeholder="原因"></textarea>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary add3" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>

    </div>
</div>
<!-- /.modal -->

<!-- 确认退款模态框（Modal） -->
<div class="modal fade" id="confirm_refund" tabindex="-1" role="dialog" aria-labelledby="myModalLabelConfirm"
     aria-hidden="true">
    <div class="modal-dialog" style="width:300px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabelConfirm">确认收货</h4>
            </div>
            <div class="modal-body" style="text-align: center;">
                确认此订单已退款？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary add4" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>

    </div>
</div>
<!-- /.modal -->

{/block}
{block name="script"}
<script>
  require(['utilAdmin','util'], function (utilAdmin,util) {  
    var allow_refund_status = [];
    switch ({$refund_status}) {
        case 0:
            // 待买家操作tab 显示待买家操作order_goods
            allow_refund_status = [2, -3];
            break;
        case 1:
            // 待卖家操作tab 显示待卖家操作order_goods
            allow_refund_status = [1, 3, 4];
            break;
        case 2:
            // 已退款tab 显示已经退款的order_goods
            allow_refund_status = [5];
            break;
        case 3:
            // 已拒绝tab 显示拒绝的order_goods
            allow_refund_status = [-1, -3];
            break;
        default :
            // 全部tab 显示需要操作的order_goods
            allow_refund_status = [1, 2, 3, 4, 5, -1, -3];
            break;
    }


    $(function () {
        util.layDate('#orderTime',true,function(value, date, endDate){
            var h=date.hours<10 ?"0"+date.hours : date.hours;
            var m=date.minutes<10 ?"0"+date.minutes : date.minutes;
            var s=date.seconds<10 ?"0"+date.seconds : date.seconds;
            var h1=endDate.hours<10 ?"0"+endDate.hours : endDate.hours;
            var m1=endDate.minutes<10 ?"0"+endDate.minutes : endDate.minutes;
            var s1=endDate.seconds<10 ?"0"+endDate.seconds : endDate.seconds;
            var date1=date.year+'-'+date.month+'-'+date.date+' '+h+":"+m+":"+s;
            var date2=endDate.year+'-'+endDate.month+'-'+endDate.date+' '+h1+":"+m1+":"+s1;

            if(value){
                $('#orderStartDate').val(date1);
                $('#orderEndDate').val(date2);
            }
            else{
                $('#orderStartDate').val('');
                $('#orderEndDate').val('');
            }

        });
        util.layDate('#payTime',true,function(value, date, endDate){
            var h=date.hours<10 ?"0"+date.hours : date.hours;
            var m=date.minutes<10 ?"0"+date.minutes : date.minutes;
            var s=date.seconds<10 ?"0"+date.seconds : date.seconds;
            var h1=endDate.hours<10 ?"0"+endDate.hours : endDate.hours;
            var m1=endDate.minutes<10 ?"0"+endDate.minutes : endDate.minutes;
            var s1=endDate.seconds<10 ?"0"+endDate.seconds : endDate.seconds;
            var date1=date.year+'-'+date.month+'-'+date.date+' '+h+":"+m+":"+s;
            var date2=endDate.year+'-'+endDate.month+'-'+endDate.date+' '+h1+":"+m1+":"+s1;
            if(value){
                $('#payStartDate').val(date1);
                $('#payEndDate').val(date2);
            }
            else{
                $('#payStartDate').val('');
                $('#payEndDate').val('');
            }

        });
        util.layDate('#deliveryTime',true,function(value, date, endDate){
            var h=date.hours<10 ?"0"+date.hours : date.hours;
            var m=date.minutes<10 ?"0"+date.minutes : date.minutes;
            var s=date.seconds<10 ?"0"+date.seconds : date.seconds;
            var h1=endDate.hours<10 ?"0"+endDate.hours : endDate.hours;
            var m1=endDate.minutes<10 ?"0"+endDate.minutes : endDate.minutes;
            var s1=endDate.seconds<10 ?"0"+endDate.seconds : endDate.seconds;
            var date1=date.year+'-'+date.month+'-'+date.date+' '+h+":"+m+":"+s;
            var date2=endDate.year+'-'+endDate.month+'-'+endDate.date+' '+h1+":"+m1+":"+s1;
            if(value){
                $('#sendStartDate').val(date1);
                $('#sendEndDate').val(date2);
            }
            else{
                $('#sendStartDate').val('');
                $('#sendEndDate').val('');
            }
            
        });
        util.layDate('#completeTime',true,function(value, date, endDate){
            var h=date.hours<10 ?"0"+date.hours : date.hours;
            var m=date.minutes<10 ?"0"+date.minutes : date.minutes;
            var s=date.seconds<10 ?"0"+date.seconds : date.seconds;
            var h1=endDate.hours<10 ?"0"+endDate.hours : endDate.hours;
            var m1=endDate.minutes<10 ?"0"+endDate.minutes : endDate.minutes;
            var s1=endDate.seconds<10 ?"0"+endDate.seconds : endDate.seconds;
            var date1=date.year+'-'+date.month+'-'+date.date+' '+h+":"+m+":"+s;
            var date2=endDate.year+'-'+endDate.month+'-'+endDate.date+' '+h1+":"+m1+":"+s1;
            if(value){
                $('#finishStartDate').val(date1);
                $('#finishEndDate').val(date2);
            }
            else{
                $('#finishStartDate').val('');
                $('#finishEndDate').val('');
            }
        });
        getOrderGoodsCount();
        LoadingInfo(1);

        //点击modal
        $("body").on('click', "a[data-target]", function () {
            var order_id = $(this).attr('data-order-id');
            var order_goods_id = $(this).attr('data-order-goods-id');
            $("#order_id").val(order_id);
            $("#order_goods_id").val(order_goods_id);
            var data_target = $(this).attr('data-target');

            if (data_target == '#judge_return') {
                getShopReturnSet();
            }
            if (data_target == '#logistics') {
                var obj = $(this);
                obj.removeAttr('data-target');
                util.confirm('物流跟踪', 'url:' + __URL(ADMINMAIN + '/order/logisticsModal?order_id=' + order_id + '&order_goods_id=' + order_goods_id, function () {}));
                obj.attr('data-target', '#logistics');
            }
        })

        //退款申请modal
        $("#judge_refund input[name=goodsRefund]").on('change', function () {
            if ($("#refund_agree").prop('checked')) {
                $(".reason").addClass('hide');
            } else {
                $(".reason").removeClass('hide');
            }
        })

        //退货申请modal
        $("#judge_return input[name=goodsReturn]").on('change', function () {
            if ($("#return_agree").prop('checked')) {
                $(".returnAddress").removeClass('hide');
                $(".reason").addClass('hide');
            } else {
                $(".returnAddress").addClass('hide');
                $(".reason").removeClass('hide');
            }
        })

        //处理回寄modal
        $("#confirm_receipt input[name=dealResult]").on('change', function () {
            if ($("#confirm").prop('checked')) {
                $(".isBlock").addClass('hide');
            } else {
                $(".isBlock").removeClass('hide');
            }
        })
    })

    //获取店铺退货地址
    function getShopReturnSet() {
        $.ajax({
            type: "POST",
            url: "{:__URL('ADMIN_MAIN/config/getShopReturnList')}",
            success: function (data) {
                var html = '';
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        html += '<option value="'+ data[i].return_id +'" >'+ data[i].consigner +' '+ data[i].province_name+data[i].city_name+data[i].dictrict_name +' '+ data[i].address +'</option>';
                    }
                    $("#address_return").html(html);
                }
            }
        });
    }

    //获取售后订单数量
    function getOrderGoodsCount() {
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/order/getordergoodscount')}",
            success: function (data) {
                $('#all_refund').html('(' + data.all + ')');
                $('#waiting_buyer_operation').html('(' + data.waiting_buyer_operation + ')');
                $('#waiting_seller_operation').html('(' + data.waiting_seller_operation + ')');
                $('#have_refunded').html('(' + data.have_refunded + ')');
                $('#have_refused').html('(' + data.have_refused + ')');
            }
        });
    }

    function isRefundStatus(refund_status) {
        if ($.inArray(refund_status, allow_refund_status) != -1  || {$refund_status} == '9') {
            // 全部的tab {$refund_status} == '9'
            return true;
        }
        return false;
    }

    function LoadingInfo(page_index) {
        $("#page_index").val(page_index);
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/order/afterorderlist')}",
            data: {
                "page_index": page_index,
                "page_size": $("#showNumber").val(),
                "start_date": $("#orderStartDate").val(),
                "end_date": $("#orderEndDate").val(),
                "pay_start_date": $("#payStartDate").val(),
                "pay_end_date": $("#payEndDate").val(),
                "consign_start_date": $("#sendStartDate").val(),
                "consign_end_data": $("#sendEndTime").val(),
                "finish_start_date": $("#finishStartDate").val(),
                "finish_end_date": $("#finishEndDate").val(),
                "user_info": $("#user_info").val(),
                "order_no": $("#order_no").val(),
                "order_status": $("#order_status").val(),
                "refund_status": $("#refund_status").val(),
                "payment_type": $("#payment_type").val(),
                "express_no": $("#express_no").val(),
                "goods_name": $("#goods_name").val()
            },
            success: function (data) {
                //alert(JSON.stringify(data["data"][1]['order_item_list']));
                var html = '';
                if (data["data"].length == 0) {
                    html += '<table class="table v-table table-auto-center mb-10"><tbody><tr align="center"><td class="h-200" colspan="7">暂无符合条件的数据记录</td></tr></tbody></table>';
                    $(".ol_tbody").html(html);
                    return true;
                }

                $.each(data["data"], function (k_order, v_order) {
                    var order_id = v_order["order_id"];//订单id
                    var order_no = v_order["order_no"];//订单编号
                    var receiver_name = v_order['receiver_name']; //买家姓名
                    var receiver_mobile = v_order['receiver_mobile']; //买家电话
                    var create_time = utilAdmin.timeStampTurnTime(v_order["create_time"]);//下单时间
                    //var shipping_type_name = v_order["shipping_type_name"];//配送方式
                    var bonus = v_order["bonus"];
                    var commission = v_order["commission"];
                    var order_money = v_order["order_money"];//订单金额
                    var shipping_money = v_order['shipping_money'] - v_order['promotion_free_shipping'];//运费
                    var order_status = v_order['order_status'];
                    var status_name = v_order['status_name'];
                    var promotion_status = v_order['promotion_status'];// 标识售后订单是否整单进行售后
                    var operation = v_order['operation'];
                    var coin_after = v_order['coin_after'];
                    var shop_after = v_order['shop_after'];
                    var row = 0;
                    $.each(v_order['order_item_list'], function (list_k, list_v) {
                        if (isRefundStatus(list_v['refund_status'])) {
                            row++;
                        }
                    })

                    html += '<table class="table v-table table-auto-center mb-10"><tbody><tr>';
                    html += '<td colspan="7" class="tr_1st">';
                    html += '<span style="padding-right: 30px">订单编号：' + order_no + '</span><span style="padding-right: 30px">下单时间：' + create_time + '</span><span style="padding-right: 30px">配送方式：' + '快递' + '</span>';
                    // if (commission) {
                    //     html += '<span style="padding-right: 30px">分销佣金：' + commission + '元</span> &nbsp;&nbsp;';
                    // }
                    // if (bonus) {
                    //     html += '<span style="padding-right: 30px">分红：' + bonus + '元</span>';
                    // }
                    html += '</td></tr>';

                    var buyer_info = false;
                    var refund_require_money = 0;
                    var refund_deduction_point = 0;
                    $.each(v_order['order_item_list'], function (k_order_goods, v_order_goods) {
                        refund_require_money = refund_require_money + Number(v_order_goods['refund_require_money']);//总退款金额
                        refund_deduction_point = refund_deduction_point + Number(v_order_goods['deduction_point']);//总退款积分
                    })
                    var refund_status=[];
                    $.each(v_order['order_item_list'], function (k_order_goods1, v_order_goods1) {
                        if(v_order_goods1["refund_status"]==5){
                            refund_status.push(1);
                        }
                    })
                    $.each(v_order['order_item_list'], function (k_order_goods, v_order_goods) {
                        var pic_cover_micro = v_order_goods["picture"]['pic_cover_mid'];//商品图
                        var goods_id = v_order_goods["goods_id"];//商品id
                        var order_goods_id = v_order_goods["order_goods_id"];
                        var goods_name = v_order_goods["goods_name"];
                        var price = v_order_goods["price"];//商品价格
                        var num = v_order_goods["num"];//购买数量
                        var order_goods_refund_status = v_order_goods["refund_status"];
                        var spec_info = v_order_goods["spec"];
                        var new_refund_operation = v_order_goods["new_refund_operation"];
                        var refund_status_name = v_order_goods["status_name"];
                        if(shop_after==1 || coin_after==1){
                            refund_status_name = '商家处理中';
                            status_name = '商家处理中';
                        }
                        if (isRefundStatus(order_goods_refund_status)) {
                            html += '<tr><td class="col-md-3">';
                            html += '<div class="media text-left">';
                            html += '<div class="media-left">';
                            html += '<p><img src="' + __IMG(pic_cover_micro) + '" style="width:60px;height:60px;"></div>';
                            html += '<div class="media-body break-word">';
                            html += '<div class="line-2-ellipsis">';
                            html += '<a class="tdTitles" href="' + __URLS('SHOP_MAIN/goods/goodsinfo&goodsid=' + goods_id) + '&website_id={$website_id}" target="_blank">' + goods_name + '</a>';
                            html += '</div>';
                            html += '<div class="small-muted line-2-ellipsis">';
                            $.each(spec_info, function (spec_k, spec_v) {
                                html += spec_v['spec_name'] + ':' + spec_v['spec_value_name'] + ' ';
                            })
                            html += '</div>';
                            html += '<div>';
                                //售后
                                if (order_goods_refund_status != 0 && promotion_status != 1 && v_order['order_item_list'].length > 1) {
                                //售后
                                    $.each(new_refund_operation, function (k_op, v_op) {
                                        html += '<a href="javascript:void(0);" data-order-id="' + order_id + '" data-order-goods-id="' + order_goods_id + '" data-refund_require_money="' + v_order_goods['refund_require_money'] + '" data-refund_deduction_point="' + v_order_goods['deduction_point'] + '" class="text-primary block ' + v_op["no"] + '">' + v_op['name'] + '</a>';
                                    })
                                }
                            html += '</div>';
                            html += '</div></div></td>';
                            html += '<td class="col-md-1">￥' + price + '</td>';
                            html += '<td class="col-md-1">' + num + '件</td>';
                            if (buyer_info == false) {
                                if (row > 1) {
                                    html += '<td rowspan="' + row + '" class="border-left col-md-2">';
                                } else {
                                    html += '<td rowspan="' + row + '" class="col-md-2">';
                                }
                                if (v_order['shipping_type'] == '2') {
                                    html += '' + v_order['buyer_name'] + '<br>' + v_order['user_name'] + '<br>' + v_order['user_tel'] + '';
                                } else {
                                    html += '' + v_order['buyer_name'] + '<br>' + receiver_name + '<br>' + receiver_mobile + '';
                                }
                                html += '</td>';
                                // if (order_status == '3' || order_status == '4') {
                                //     html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-success">' + status_name + '</span></p>';
                                // } else {
                                //     html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-danger">' + status_name + '</span></p>';
                                // }
                                if($("#refund_status").val()==2 && refund_status.length<v_order['order_item_list'].length){
                                    html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-grey">' + refund_status_name + '</span></p>';
                                }else{
                                    if(order_status == '0'){
                                        html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-red">' + status_name + '</span></p>';
                                    }else if(order_status == '1'){
                                        html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-skyBlue">' + status_name + '</span></p>';
                                    }else if(order_status == '2'){
                                        html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-orange">' + status_name + '</span></p>';
                                    }else if(order_status == '3' || order_status == '4'){
                                        html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-green">' + status_name + '</span></p>';
                                    }else if(order_status == '5'){
                                        html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-grey">' + status_name + '</span></p>';
                                    }else{
                                        html += '<td rowspan="' + row + '" class="col-md-1"><p class="mb-04"><span class="label label-orange2">' + status_name + '</span></p>';
                                    }
                                }


                                html += '<p><a href="' + __URL('ADMIN_MAIN/order/orderdetail?order_id=' + order_id) + '">订单详情</a></p></td>';
                                html += '<td class="text-right col-md-2" rowspan="' + row + '">';
                                if(v_order['presell_id']){
                                	html += '定金：￥' + v_order['first_money'] + '<br> 尾款：￥' + v_order['final_money'] + '<br>';
                                }else{
                                	html += '商品总额：￥' + v_order['goods_money'] + '<br>';
                                }
                                if(v_order['deduction_money']>0){
                                	html += '积分抵扣：￥' + v_order['deduction_money'] + '<br>';
                                }
                                	html += '优惠：￥' + v_order['order_promotion_money'] + '<br>';
                               		html += '运费：￥' + shipping_money + '';
                                if(v_order['presell_id']){
                                	if(v_order['money_type']==1){
                                		html += '<br>实收金额：￥' + v_order['pay_money'] + '<br>';
                                	}else if(v_order['money_type']==2){
                                		html += '<br>实收金额：￥' + order_money + '<br>';
                                	}
                                }else{
                                	html += '<br>实收金额：￥' + order_money + '<br>';
                                }
                                html += '</td>';
                                html += '<td rowspan="' + row + '" class="col-md-2 fs-0 operationLeft">';
                                if (promotion_status == 1 && operation) {
                                    $.each(operation, function (k_status, v_status) {
                                        var data_goods = '';
                                        if(v_status["no"] == 'logistics'){
                                            data_goods = 'data-order-goods-id=' + order_goods_id;
                                        }
                                        if(v_order['order_status']==5 && v_status["no"]=='delete_order'){
                                            //html += '<a class="btn-operation text-red1" href="javascript:void(0);" data-order-id="' + order_id + '" '+data_goods+'  data-toggle="modal" data-target="#' + v_status["no"] + '">' + v_status['name'] + '</a>';
                                         }
                                            // else if(v_status['no']=='judge_refund'){
                                        //             html += '<a href="javascript:void(0);" data-order-id="'+order_id+'" class="text-primary block ' + v_status["no"] + '" data-refund_require_money="' + refund_require_money + '" data-refund_deduction_point="' + refund_deduction_point + '" data-payment-type="' + v_order['payment_type'] + '">' + v_status['name'] + '</a>';
                                        //     	}
                                        else{
                                            html += '<a class="btn-operation" href="javascript:void(0);" data-order-id="' + order_id + '" '+data_goods+' data-toggle="modal" data-target="#' + v_status["no"] + '">' + v_status['name'] + '</a>';
                                        }
                                    })
                                }
                                if (promotion_status != 1 && new_refund_operation  && v_order['order_item_list'].length == 1) {
                                    $.each(new_refund_operation, function (k_op, v_op) {
                                        html += '<a class="btn-operation" href="javascript:void(0);" data-order-id="' + order_id + '" data-order-goods-id="' + order_goods_id + '" data-toggle="modal" data-target="#' + v_op["no"] + '">' + v_op['name'] + '</a>';
                                    })
                                }
                                html += '</td>';
                                html += '</tr>';
                                buyer_info = true;
                            }
                        }
                    })
                    html += '</tbody></table>';
                })
                $(".ol_tbody").html(html);
                utilAdmin.tips();
                utilAdmin.page('.M-box3', data['total_count'], data["page_count"], page_index, LoadingInfo);
            }
        });
    }

    //订单数据导出
    function dataExcel() {
        var url='url:'+__URL('ADMIN_MAIN/order/dataExcel');
        util.confirm('订单导出',url,function(){
        	var ids = '';
        	$(".excel-list .field-item").each(function(){
            	var id = $(this).data('id');
            	ids += id + ',';
        	});
            var start_date = $("#orderEndDate").val();
            var end_date = $("#orderStartDate").val();
            var pay_start_date = $("#payStartDate").val();
            var pay_end_date = $("#orderEndDate").val();
            var consign_start_date = $("#payEndDate").val();
            var consign_end_date = $("#sendStartDate").val();
            var finish_start_date = $("#finishStartDate").val();
            var finish_end_date = $("#finishEndDate").val();
            var user_info = $("#user_info").val();
            var order_no = $("#order_no").val();
            var order_status = $("#order_status").val();
            var payment_type = $("#payment_type").val();
            var refund_status = $("#refund_status").val();
            var express_no = $("#express_no").val();
            var goods_name =  $("#goods_name").val()
			if(ids.length==0){
				util.message('请添加模板字段');
				return false;
			}
            window.location.href = __URL("ADMIN_MAIN/order/orderDataExcel" +
                "?start_date=" + start_date +
                "&end_date=" + end_date +
                "&pay_start_date=" + pay_start_date +
                "&pay_end_date=" + pay_end_date +
                "&consign_start_date=" + consign_start_date +
                "&consign_end_date=" + consign_end_date +
                "&finish_start_date=" + finish_start_date +
                "&finish_end_date=" + finish_end_date +
                "&user_info=" + user_info +
                "&order_no=" + order_no +
                "&order_status=" + order_status +
                "&payment_type=" + payment_type +
                "&refund_status=" + refund_status +
                "&express_no=" + express_no +
                "&goods_name=" + goods_name +
                "&ids=" + ids + 
                "&type=3"
            );
        },'xlarge');
    }

    //退款申请操作
    function judgeRefund() {
        var order_id = $("#order_id").val();
        var order_goods_id = $("#order_goods_id").val();
        if ($("#refund_agree").prop('checked')) {
            agreeRefund(order_id, order_goods_id);
        } else {
            var reason = $("#judge_refund_reason").val();
            refuseRefundType(order_id, order_goods_id, reason, 1)
        }
    }

    //同意退款操作
    function agreeRefund(order_id, order_goods_id,return_id=0) {
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/Order/orderGoodsRefundAgree')}",
            async: true,
            data: {'order_id': order_id, "order_goods_id": order_goods_id,"return_id":return_id},
            success: function (data) {
                if (data['code'] > 0) {
                    utilAdmin.message(data['message'],"success", function () {
                        LoadingInfo($("#page_index").val());
                    });
                } else {
                    utilAdmin.message(data["message"],"danger");
                }
            }
        });
    }

    // 拒绝退款操作
    function refuseRefundType(order_id, order_goods_id, reason, type) {
        if (type == 1) {
            var refund_url = "{:__URL('ADMIN_MAIN/order/ordergoodsrefuseonce')}";
        } else {
            var refund_url = "{:__URL('ADMIN_MAIN/order/ordergoodsrefuseforever')}";
        }
        $.ajax({
            type: "post",
            url: refund_url,
            data: {
                'order_id': order_id,
                'order_goods_id': order_goods_id,
                'reason': reason
            },
            success: function (data) {
                if (data['code'] > 0) {
                    utilAdmin.message("已拒绝","success", function () {
                        LoadingInfo($("#page_index").val());
                    });
                } else {
                    utilAdmin.message(data["message"],"danger");
                }
            }
        });
    }

    //退货申请操作(和退款申请一样的处理)
    function judgeReturn() {
        var order_id = $("#order_id").val();
        var order_goods_id = $("#order_goods_id").val();
        if ($("#return_agree").prop('checked')) {
        	var return_id = $("#address_return").val();
        	if(return_id==0){
				util.message('请选择退货地址');
				return false;
        	}
            agreeRefund(order_id, order_goods_id,return_id);
        } else {
            var reason = $("#reject_return_reason").val();
            refuseRefundType(order_id, order_goods_id, reason, 1)
        }
    }

    function judgeReceipt() {
        var order_id = $("#order_id").val();
        var order_goods_id = $("#order_goods_id").val();
        if ($("#confirm").prop('checked')) {
            agreeReturn(order_id, order_goods_id);
        } else {
            var reason = $("#refuse_receipt_reason").val();
            refuseRefundType(order_id, order_goods_id, reason, 1);
        }
    }

    // 确认签收
    function agreeReturn(order_id, order_goods_id) {
        $.ajax({
            type: "post",
            url: "{:__URL('ADMIN_MAIN/order/ordergoodsconfirmreceive')}",
            data: {'order_id': order_id, "order_goods_id": order_goods_id},
            success: function (data) {
                if (data['code'] > 0) {
                    utilAdmin.message("已签收", "success", function () {
                        LoadingInfo($("#page_index").val());
                    });
                } else {
                    utilAdmin.message(data["message"],"danger");
                }
            }
        });
    }

    //确认退款
    function orderGoodsConfirmRefund() {
        var order_id = $("#order_id").val();
        var order_goods_id = $("#order_goods_id").val()
        $("#confirm_refund").modal("hide")
        $.ajax({
            type: "post",
            url: __URL(ADMINMAIN + "/order/ordergoodsconfirmrefund"),
            data: {
                'order_id': order_id,
                "order_goods_id": order_goods_id
            },
            success: function (data) {
                if (data['code'] > 0) {
                    utilAdmin.message("退款已成功，请注意查看", "success", function () {
                        LoadingInfo($("#page_index").val());
                    });
                } else {
                    utilAdmin.message(data['message'], "danger");
                }
            }
        });
    }

      $('body').on('click', '.add1', function () {
          judgeReceipt();
      });
      $('body').on('click', '.add2', function () {
          judgeRefund()
      });
      $('body').on('click', '.add3', function () {
          judgeReturn()
      });
      $('body').on('click', '.add4', function () {
          orderGoodsConfirmRefund()
      });
      $('body').on('click', '#search_button', function () {
          LoadingInfo(1)
      });
      $('body').on('click', '#export_button', function () {
          dataExcel()
      });
  })
</script>
{/block}